package cn.edu.fzu.homemaking.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.fzu.homemaking.annotation.LogAop;
import cn.edu.fzu.homemaking.api.OrderApi;
import cn.edu.fzu.homemaking.api.SsoApi;
import cn.edu.fzu.homemaking.domain.vo.CountCompany;
import cn.edu.fzu.homemaking.service.SysCompanyService;
import cn.edu.fzu.homemaking.web.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author yifan
 * @date 2023/4/14
 */
@Api(tags = "sys-统计接口")
@RestController
@RequestMapping("/api/sys")
public class SysStatisticController {

    @Resource
    private SysCompanyService sysCompanyService;

    @Resource
    private SsoApi            ssoApi;

    @Resource
    private OrderApi          orderApi;

    @ApiOperation(value = "统计公司数量")
    @GetMapping("/auth/countCompany")
    public Result countCompany() {
        CountCompany countCompany = sysCompanyService.countCompany();
        return new Result(countCompany);
    }


    @LogAop
    @ApiOperation(value = "公司员工和顾客数量统计")
    @GetMapping("/auth/countUser")
    public Result countUser() {
        Result result = ssoApi.countUser();
        return result;
    }


    @LogAop
    @ApiOperation(value = "订单统计概览")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间（订单创建时间）"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（订单创建时间）")
    })
    @GetMapping("/auth/countOrder")
    public Result countOrder(String startTime, String endTime) {
        Result result = orderApi.count(startTime, endTime);
        return result;
    }


    @LogAop
    @ApiOperation(value = "订单按月统计")
    @GetMapping("/auth/countOrderByMonth")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间（订单创建时间）"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（订单创建时间）")
    })
    public Result countByMonth(String startTime, String endTime) {
        Result result = orderApi.countByMonth(startTime, endTime);
        return result;
    }

    @LogAop
    @ApiOperation(value = "订单按日统计")
    @GetMapping("/auth/countOrderByDay")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间（订单创建时间）"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（订单创建时间）")
    })
    public Result countByDay(String startTime, String endTime) {
        Result result = orderApi.countByDay(startTime, endTime);
        return result;
    }

}
